package ar.edu.caece.compiler.grammars.sample2.factories;

import ar.edu.caece.compiler.grammars.sample2.tokens.TokenVisitorInterface;
import ar.edu.caece.compiler.model.LexicalAnalyzer;


// E1 -> E1p | lambda
public class E1Factory extends AbstractTokenVisitorFactory{

	private static E1Factory INSTANCE;
	private LambdaFactory lambdaFactory;
	private E1pFactory e1pFactory;
	
	private Initializer initializer = new Initializer() {

		@Override
		public void init() {
			initializer = NoOperationInitializer.getInstance();
			lambdaFactory = LambdaFactory.getInstance();
			e1pFactory = E1pFactory.getInstance();
			
		}
		
	};
	
	public E1Factory(LexicalAnalyzer analizadorLexico) {
		super(analizadorLexico);
		// TODO Auto-generated constructor stub
	}

	public E1Factory() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public TokenVisitorInterface makeChainedVisitor(
			TokenVisitorInterface siguiente) throws Exception {
		initializer.init();
		return e1pFactory.makeChainedVisitor(lambdaFactory.makeChainedVisitor(siguiente));
	}

	@Override
	public TokenVisitorInterface makeVisitor() throws Exception {
		initializer.init();
		return e1pFactory.makeChainedVisitor(lambdaFactory.makeVisitor());
	}

	public static E1Factory getInstance() {
		if(INSTANCE==null) INSTANCE = new E1Factory();
		return INSTANCE;
	}

}
